<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib uri="/WEB-INF/tld/pageutil.tld" prefix="pu"%>
<%@taglib uri="/WEB-INF/tld/pageable.tld" prefix="pageable"%>
<%@taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jstl/core_rt" prefix="c-rt"%>
<%@taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt-rt"%>
<c-rt:set var="tp" value="${pu:pageableTag('tpp', 10, 10)}"/>
<c-rt:choose>
<c-rt:when test="${empty param.priority && empty param.status && empty param.questionType && empty param.approveStatus}">
${pu:reqSet('hql', 'from WorkOrder w where 
(
	(
		(
			(w.status!=?)
			and
			(
				(w.owner.username=?) 
				or 
				(w.approveGroup=? and w.approveStatus=?)
			)
		)
	)
)

order by status asc, createDate desc, forwardFinishTime desc
') }
${pu:listAdd('params', pu:toInteger(2)) }
${pu:listAdd('params', pu:username()) }
${pu:listAdd('params', pu:user().group.code) }
${pu:listAdd('params', pu:toInteger(0)) }
<c-rt:set var="hqlR">
${hql }
</c-rt:set>
${pu:reqSet('results', pu:queryByHql(hqlR, pu:arrayGet('params'), tp)) }





</c-rt:when>
<c-rt:otherwise>
${pu:reqSet('hql', 'from WorkOrder w where 
(
	(
		(
			(w.owner.username=?) 
			or 
			(w.approveGroup = ? and w.approveStatus=?)
		)
	)
)
 ')}


${pu:reqSet('hqlOrder','
order by status asc, createDate desc, forwardFinishTime desc') }

${pu:listAdd('params', pu:username()) }
${pu:listAdd('params', pu:user().group.code) }
${pu:listAdd('params', pu:toInteger(0)) }

<c-rt:if test="${!empty param.priority}">
${pu:reqSet('hql1', ' and priority=? ') }
${pu:listAdd('params', pu:toInteger(param.priority)) }
</c-rt:if>
<c-rt:if test="${!empty param.status}">
${pu:reqSet('hql2', ' and status=? ') }
${pu:listAdd('params', pu:toInteger(param.status)) }
</c-rt:if>
<c-rt:if test="${!empty param.questionType}"> 
<c-rt:if test="${param.questionType=='CommonQuestion_product'}">
<c-rt:set var="hql3" scope="request">
 and w.question.type=? and w.question.extraValue['isProductQAA'].value=? 
</c-rt:set>
${pu:listAdd('params', 'CommonQuestion') }
${pu:listAdd('params', 'true') }

</c-rt:if>
<c-rt:if test="${param.questionType=='CommonQuestion'}">
<c-rt:set var="hql3" scope="request">
 and w.question.type=? and w.question.extraValue['isProductQAA'].value!=? 
</c-rt:set>
${pu:listAdd('params', 'CommonQuestion') }
${pu:listAdd('params', 'true') }

</c-rt:if>
<c-rt:if test="${param.questionType!='CommonQuestion_product' && param.questionType!='CommonQuestion'}">
${pu:reqSet('hql3', ' and w.question.type=? ') }
${pu:listAdd('params', param.questionType) }
</c-rt:if>
</c-rt:if>
<c-rt:if test="${!empty param.approveStatus}">
${pu:reqSet('hql4', ' and approveStatus=?') }
${pu:listAdd('params', param.approveStatus) }
</c-rt:if>
<c-rt:set var="hqlR">
${hql }${hql1 }${hql2 }${hql3 }${hql4 }${hqlOrder }
</c-rt:set>
${pu:reqSet('results', pu:queryByHql(hqlR, pu:arrayGet('params'), tp)) }




</c-rt:otherwise>
</c-rt:choose>
<c-rt:set var="hqlUser" value="from User where group.code=?"/>
<c-rt:set var="paramsUser" value="${pu:addToList('parasUser', 'C.01')}"/>
<c-rt:set var="users" value="${pu:queryByHql(hqlUser, paramsUser, null)}"/>
${pu:reqSet('menu', pu:get('com.yaodian100.core.menu.entity.Menu', 'WorkOrder.status')) }
<br />
<h1>我的工作

</h1>

<form name="workOrderForm">
<table>
<tr>
<td>
处理等级:<select name="priority">
<option value="">请选择</option>
<option value="0" <c-rt:if test="${param.priority == '0'}">selected="selected"</c-rt:if>>函件</option>
<option value="1" <c-rt:if test="${param.priority == '1'}">selected="selected"</c-rt:if>>一般件</option>
<option value="2" <c-rt:if test="${param.priority == '2'}">selected="selected"</c-rt:if>>急件</option>
<option value="3" <c-rt:if test="${param.priority == '3'}">selected="selected"</c-rt:if>>特急件</option>
</select>
状态:
<select name="status">
<option value="">请选择</option>
<c-rt:forEach items="${menu.options}" var="option">
<option value="${option.value.code }" <c-rt:if test="${option.value.code==param.status }">selected="selected"</c-rt:if>>${option.value.name }</option>
</c-rt:forEach>
</select>
问题类型：
<select name="questionType">
<option value="">请选择</option>
<option value="CommonQuestion" <c-rt:if test="${param.questionType=='CommonQuestion' }">selected="selected"</c-rt:if>>客服问答</option>
<option value="CommonQuestion_product" <c-rt:if test="${param.questionType=='CommonQuestion_product' }">selected="selected"</c-rt:if>>商品问答</option>
<option value="PayByProductArrive" <c-rt:if test="${param.questionType=='PayByProductArrive' }">selected="selected"</c-rt:if>>货到付款审核</option>
<option value="ReturnProductApply" <c-rt:if test="${param.questionType=='ReturnProductApply' }">selected="selected"</c-rt:if>>退货申请</option>
<option value="ChangeProductException" <c-rt:if test="${param.questionType=='ChangeProductException' }">selected="selected"</c-rt:if>>换货单（异常）</option>
<option value="ReturnProductException" <c-rt:if test="${param.questionType=='ReturnProductException' }">selected="selected"</c-rt:if>>退货单（异常）</option>
<option value="OutOfStock" <c-rt:if test="${param.questionType=='OutOfStock' }">selected="selected"</c-rt:if>>断／缺货</option>

</select>
审核状态：
<select name="approveStatus">
<option value="">请选择</option>
<option value="0" <c-rt:if test="${param.approveStatus=='0' }">selected="selected"</c-rt:if>>待审核</option>
<option value="1" <c-rt:if test="${param.approveStatus=='1' }">selected="selected"</c-rt:if>>已核可</option>
<option value="2" <c-rt:if test="${param.approveStatus=='2' }">selected="selected"</c-rt:if>>已注销</option>

</select>
<input type="button" id="searchWorkOrder" value="search"/></td><td></td>
</tr>
</table>
</form>

<table class="tb-1" width="100%">
		<thead>
			<tr>
				<th></th>
				<th>ID</th>
				<th>前单ID</th>
				<th>问题单编号</th>
				<th>订单编号</th>
				<th>处理等级</th>
				<th>状态</th>
				<th>类型</th>
				<th>短描述</th>
				
				<th>审核状态</th>
				<th>建立日期</th>
				<th>转单回覆日期</th>
			</tr>
		</thead>
		<tbody>
			<c-rt:forEach items="${results}" var="result" varStatus="rows_index">
			<c-rt:set var="theStyle" scope="request">
			style="background-color:#ffffff"
			</c-rt:set>
			<c-rt:if test="${pu:subDateInHour(pu:currentDate(), result.createDate)>24}">
			<c-rt:set var="theStyle" scope="request">
			style="background-color:#aaffff"
			</c-rt:set>
			</c-rt:if>
			<c-rt:if test="${pu:subDateInHour(pu:currentDate(), result.createDate)>48}">
			<c-rt:set var="theStyle" scope="request">
			style="background-color:#ffffaa"
			</c-rt:set>
			</c-rt:if>
			<c-rt:if test="${pu:subDateInHour(pu:currentDate(), result.createDate)>72}">
			<c-rt:set var="theStyle" scope="request">
			style="background-color:#ffaaff"
			</c-rt:set>
			</c-rt:if>
			<c-rt:if test="${result.status==2}">
			<c-rt:set var="theStyle" scope="request">
			style="background-color:#ffffff"
			</c-rt:set>
			</c-rt:if>
			<c-rt:set var="domain" value="${pu:get('com.yaodian100.crm.cs.entity.Question', result.domainId)}"/>
				<tr class="${rows_index.count % 2 == 0 ? 'bg-yl' : ''}" ${theStyle }>
					<td>
					<input type="button" value="追踪" onclick="doAR('<%=application.getContextPath() %>/workOrder/page.do?iamlazy=trace&AJAX=true&refreshZone=main&id=${result.id}', 'dialog');openDialog('trace', '', 700, 300)"/>
					<input type="button" value="明细" onclick="location.href='<%=application.getContextPath() %>/cs/page.do?iamlazy=viewQuestion&id=${result.id}'"/>
					
					</td>
					<td>${result.id }</td>
					<td>${result.parent.id }</td>
					<td>${domain.id }</td>
					<td>${result.question.extraValue['orderId'].value }</td>
					<td>
					<c-rt:if test="${result.priority==0}">
					函件
					</c-rt:if>
					<c-rt:if test="${result.priority==1}">
					一般件
					</c-rt:if>
					<c-rt:if test="${result.priority==2}">
					急件
					</c-rt:if>
					<c-rt:if test="${result.priority==3}">
					特急件
					</c-rt:if>
					</td>
					<td>${pu:menuOption('WorkOrder.status', pu:toString(result.status)).name }</td>
					<td>
					<c-rt:if test="${domain.type.name=='CommonQuestion' }">
						<c-rt:if test="${domain.extraValue['isProductQAA'].value=='true' }">
							商品问答
						</c-rt:if>
						<c-rt:if test="${domain.extraValue['isProductQAA'].value!='true' }">
							客服问答
						</c-rt:if>
					</c-rt:if>
					<c-rt:if test="${domain.type.name!='CommonQuestion' }">
					${domain.type.description }
					</c-rt:if>
					</td>
					<td>${result.shortDesc }</td>
					
					<td>
					<c-rt:if test="${result.approveStatus==0 }">
					待审核
					</c-rt:if>
					<c-rt:if test="${result.approveStatus==1 }">
					已核可
					</c-rt:if>
					<c-rt:if test="${result.approveStatus==2 }">
					<span style="color:red">已注销</span>
					</c-rt:if>
					</td>
					<td>
					<fmt-rt:formatDate value="${result.createDate }" pattern="yyyy-MM-dd HH:mm"/>
					</td>
					<td>
					${pu:reqSet('replyHql', 'from WorkOrder where parent.id=?') }
					${pu:reqSet('replyList', null) }
					${pu:listAdd('replyList', result.id) }
					${pu:reqSet('replyWorkOrder', pu:queryByHql(replyHql, pu:arrayGet('replyList'), null)) }
					
					<c-rt:if test="${!empty replyWorkOrder}">
					<c-rt:if test="${!empty replyWorkOrder[0].finishTime}">
					<fmt-rt:formatDate value="${replyWorkOrder[0].finishTime}" pattern="yyyy-MM-dd HH:mm"/>
					</c-rt:if>
					<c-rt:if test="${empty replyWorkOrder[0].finishTime}">
					<b>尚未回覆</b>
					</c-rt:if>
					</c-rt:if>
					<c-rt:if test="${empty replyWorkOrder}">
					未转单
					</c-rt:if>
					</td>
				</tr>
			</c-rt:forEach>
		</tbody>
	</table>
<c-rt:set var="url">
<%=application.getContextPath() %>/workOrder/page.do
</c-rt:set>
<pageable:Pageable url="${url}" parameter="iamlazy=myTask" escapeparams="iamlazy,refreshZone,AJAX" formname="woForm" key="tpp"></pageable:Pageable>
<table width="100%">
<tr>
<td align="right">
${pu:reqSet('currentPage', param.tpp_pageable_currentPage) }
<c-rt:if test="${empty param.tpp_pageable_currentPage}">
${pu:reqSet('currentPage', 1) }
</c-rt:if>
目前在第${currentPage }页, 资料共${tp.totalRecords }笔</td>
</tr>
</table>
<script>
$(document).ready(function(){
	$('#searchWorkOrder').click(function(){
		doAR('<%=application.getContextPath() %>/workOrder/page.do?iamlazy=myTask&AJAX=true&refreshZone=main', 'main', 'workOrderForm');
	});
});
</script>